package com.android.duininsuoai.fragment;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.duininsuoai.R;
import com.android.duininsuoai.activity.mine.LoginActivity;
import com.android.duininsuoai.adapt.MytimeViewHolder;
import com.android.duininsuoai.model.auction.AuctionActivityData;
import com.android.duininsuoai.model.auction.AuctionActivitySendData;
import com.android.duininsuoai.model.auction.AuctionResultData;
import com.android.duininsuoai.model.auction.Auction_JoinBackData;
import com.android.duininsuoai.model.auction.Auction_JoinSendData;
import com.android.duininsuoai.model.auction.UpdateAuctionBean;
import com.android.duininsuoai.service.WebSocketService1;
import com.android.duininsuoai.utils.LoginState;
import com.android.duininsuoai.utils.ObjectUtils;
import com.android.duininsuoai.view.recycleview.CustomLoadMoreView;
import com.android.duininsuoai.view.recycleview.CustomRecycleView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/9/15.
 */

public class Fragment_AllProduct extends Fragment implements BaseQuickAdapter.RequestLoadMoreListener {


    @BindView(R.id.main_top_bg)
    Toolbar mainTopBg;
    @BindView(R.id.listView)
    CustomRecycleView mRecyclerView;
    @BindView(R.id.swipe_refresh_layout)
    SwipeRefreshLayout mRefreshLayout;
    @BindView(R.id.click_resetnetwork)
    LinearLayout clickResetnetwork;
    @BindView(R.id.progress)
    RelativeLayout progress;
    @BindView(R.id.no_data_tv)
    TextView noDataTv;
    @BindView(R.id.no_data)
    RelativeLayout noData;


    private View rootView;
    private AdaptList adapter;
    private LayoutInflater inflater;
    private boolean networkConnected;
    private FragmentActivity mcontext;
    private LinearLayoutManager layoutmanager = new LinearLayoutManager(mcontext);
    private ArrayList<AuctionActivityData.ListBean> listdata = new ArrayList<>();
    private ArrayList<AuctionActivityData.ListBean> temporary_listdata = new ArrayList<>();
    private Gson gson = new Gson();
    private String gsonstring="";
    private WebSocketService1 service;
    private BroadcastReceiver mBroadcastReceiver;
    private Message message,message2,message3,message4;
    private Auction_JoinSendData auction_joinSendData = new Auction_JoinSendData();
    private AuctionActivitySendData auctionActivitySendData = new AuctionActivitySendData();
    private AuctionActivityData auctionactivitydata;
    private Auction_JoinBackData auction_joinBackData = new Auction_JoinBackData();
    private AuctionResultData auctionResultData = new AuctionResultData();
    private HashMap<String,MytimeViewHolder> myViewHolderList = new HashMap<>();
    private HashMap<String,Boolean> isStartMap = new HashMap<>();
    private HashMap<String,UpdateAuctionBean> updateBean = new HashMap<>();
    private HashMap<String,UpdateAuctionBean> lastperiodBean = new HashMap<>();
    private static final String ARG_PARAM2 = "param2";
    private String cid;
    private int page=1;
    private int mid;
    private String token;
    private boolean isPrepared ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            cid = getArguments().getString(ARG_PARAM2);
        }
    }
    @Override
    public void onResume()
    {
        super.onResume();
        if(!LoginState.getInstance().getid(mcontext).equals("")&&LoginState.getInstance().getid(mcontext)!=null) {
            mid = Integer.parseInt(LoginState.getInstance().getid(mcontext));
            token = LoginState.getInstance().getUserInfo(mcontext,2);
            // SetDou();
        }
    }
    public static Fragment_AllProduct newInstance( String cid) {
        Fragment_AllProduct fragment = new Fragment_AllProduct();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM2, cid);
        fragment.setArguments(args);
        return fragment;
    }



    /**
     * 视图是否已经初初始化
     */
    protected boolean isInit = false;
    protected boolean isLoad = false;
    protected final String TAG = "LazyLoadFragment";



    protected void initData() {
        myViewHolderList.clear();
        temporary_listdata.clear();
        broadcastReceive();
        networkConnected = ObjectUtils.isNetworkConnected(mcontext);
        if (networkConnected) {
            auctionActivitySendData.setType("get_auctions");
            auctionActivitySendData.setPage(page);
            auctionActivitySendData.setPer_page(10);
            auctionActivitySendData.setCid(Integer.parseInt(cid));
            gsonstring = gson.toJson(auctionActivitySendData);
            service.setCid(cid);
            service.sendMsg(gsonstring);

        } else {


            ObjectUtils.GetDataNet(clickResetnetwork, progress, 4);
        }
    }
    /**
     * 是否可以加载数据
     * 可以加载数据的条件：
     * 1.视图已经初始化
     * 2.视图对用户可见
     */
    private void isCanLoadData() {
        if (!isInit) {
            return;
        }
        if (getUserVisibleHint()) {
            initData();
            handler1.postDelayed(mRunnable,100);
            isLoad = true;
        } else {
            if (isLoad) {
                service = null;
                handler1.removeCallbacks(mRunnable);
                getActivity().unregisterReceiver(mBroadcastReceiver);
                mBroadcastReceiver  = null;
                //stopLoad();
            }
        }
    }
    /**
     * 视图销毁的时候讲Fragment是否初始化的状态变为false
     */
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        isInit = false;
        isLoad = false;

    }
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        this.inflater = inflater;
        networkConnected = ObjectUtils.isNetworkConnected(getActivity());
            rootView = inflater.inflate(R.layout.layout_recycle_directbuy_tablist, container, false);
            ButterKnife.bind(this, rootView);
        isInit = true;
        mcontext = getActivity();
        mainTopBg.setVisibility(View.GONE);
        initRecycle();
        ReFreshData();
        /**初始化的时候去加载数据**/
        isCanLoadData();

        return rootView;
    }
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        isCanLoadData();
    }
    private void initRecycle() {
        adapter = new AdaptList(mcontext, null, "0");
        adapter.setLoadMoreView(new CustomLoadMoreView());
        adapter.setOnLoadMoreListener(this, mRecyclerView);
        mRecyclerView.setLayoutManager(layoutmanager);
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.GetToTop((ImageView) rootView.findViewById(R.id.top), 0);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter1, View view, int position) {
            }
        });
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public boolean onItemChildClick(BaseQuickAdapter adapter1, View view, int position) {
                switch (view.getId()) {
                    case R.id.rightnow_openteam:
                        if (LoginState.getInstance().isLogin(mcontext)) {
                            auction_joinSendData.setType("join_auction");
                            auction_joinSendData.setId(Integer.parseInt(adapter.getData().get(position).getId()));
                            auction_joinSendData.setMid(mid);
                            auction_joinSendData.setToken(token);
                            gsonstring = gson.toJson(auction_joinSendData);
                            service.sendMsg(gsonstring);
                        }
                        else
                        {
                            startActivity(new Intent(mcontext, LoginActivity.class));
                        }
                        break;

                }
                return false;
            }
        });
    }
    private void ReFreshData() {
        if (mRefreshLayout != null) {

            mRefreshLayout.setColorSchemeResources(R.color.app_title);
            mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    networkConnected = ObjectUtils.isNetworkConnected(mcontext);
                    if (networkConnected) {
                        mRefreshLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                page = 1;
                                myViewHolderList.clear();
                                temporary_listdata.clear();
                                listdata.clear();
                                auctionActivitySendData.setType("get_auctions");
                                auctionActivitySendData.setPage(page);
                                auctionActivitySendData.setPer_page(10);
                                auctionActivitySendData.setCid(Integer.parseInt(cid));
                                gsonstring = gson.toJson(auctionActivitySendData);
                                service.setCid(cid);
                                service.sendMsg(gsonstring);
                            }
                        }, 1000);
                    } else {
                        ObjectUtils.toast(mcontext, "网络连接出现异常");
                        mRefreshLayout.setRefreshing(false);
                    }
                }
            });
        }
    }

    @OnClick(R.id.click_resetnetwork_refresh)
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.click_resetnetwork_refresh:
                ObjectUtils.GetDataNet(clickResetnetwork, progress, 3);
                page = 1;
                myViewHolderList.clear();
                temporary_listdata.clear();
                listdata.clear();
                auctionActivitySendData.setType("get_auctions");
                auctionActivitySendData.setPage(page);
                auctionActivitySendData.setPer_page(10);
                auctionActivitySendData.setCid(Integer.parseInt(cid));
                gsonstring = gson.toJson(auctionActivitySendData);
                service.setCid(cid);
                service.sendMsg(gsonstring);
                break;

        }
    }

    @Override
    public void onLoadMoreRequested() {
        page = page + 1;
        auctionActivitySendData.setType("get_auctions");
        auctionActivitySendData.setPage(page);
        auctionActivitySendData.setPer_page(10);
        auctionActivitySendData.setCid(Integer.parseInt(cid));
        gsonstring = gson.toJson(auctionActivitySendData);
        service.setCid(cid);
        service.sendMsg(gsonstring);
    }
    //设置广播监听
    private void broadcastReceive()
    {

        service = WebSocketService1.getInstance();
        // service.sendMsg(get_menus);
        mBroadcastReceiver = new BroadcastReceiver(){
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                //更新竞买返回消息
                if(action.equals(WebSocketService1.ACTION_NOT1)){
                    Intent intents = mcontext.getIntent();
                    auctionResultData = (AuctionResultData)intent.getBundleExtra("bundle").getSerializable("AuctionResult");
                    if(auctionResultData!=null)
                    {
                            DealWithResult();
                    }
                }

                //更新商品列表
                if(action.equals(WebSocketService1.ACTION_AUCTION1))
                {
                    boolean isUpdateUsername =false;
                    auctionactivitydata = (AuctionActivityData) intent.getBundleExtra("bundle2").getSerializable("AuctionGetAuctions");
                    String match_id = intent.getBundleExtra("bundle2").getString("AuctionGetAuctionsCid");
                    if(auctionactivitydata.getList()!=null) {

//                        if(auctionactivitydata.getList().get(0).getMid()!=null)
//                        {
//                            midd = Integer.parseInt(auctionactivitydata.getList().get(0).getMid());
//                        }
//                        if(midd>0)
//                        {
//                            isUpdateUsername =true;
//                        }
                        listdata = new ArrayList<>();
                        for (int i = 0; i < auctionactivitydata.getList().size(); i++) {
//                            if(isUpdateUsername)
//                            {
////                                   if (auctionactivitydata.getList().get(i).getUsername() != null && !auctionactivitydata.getList().get(i).getUsername().equals(""))
////                                   {
////                                       currentlyUser.put(auctionactivitydata.getList().get(i).getId(), auctionactivitydata.getList().get(i).getUsername());
////                                   }
//                            }
//                            else {
                            if(match_id.equals(cid))
                            {
                                temporary_listdata.add(new AuctionActivityData.ListBean(AuctionActivityData.ListBean.THREE, auctionactivitydata.getList().get(i).getId()
                                        , auctionactivitydata.getList().get(i).getPeriod(), auctionactivitydata.getList().get(i).getTitle()
                                        , auctionactivitydata.getList().get(i).getThumb(), auctionactivitydata.getList().get(i).getPrice()
                                        , auctionactivitydata.getList().get(i).getTime() * 1000, auctionactivitydata.getList().get(i).getStart() * 1000
                                        , auctionactivitydata.getList().get(i).getMid(), auctionactivitydata.getList().get(i).getUsername()));

                            listdata.add(new AuctionActivityData.ListBean(AuctionActivityData.ListBean.THREE, auctionactivitydata.getList().get(i).getId()
                                    , auctionactivitydata.getList().get(i).getPeriod(), auctionactivitydata.getList().get(i).getTitle()
                                    , auctionactivitydata.getList().get(i).getThumb(), auctionactivitydata.getList().get(i).getPrice()
                                    , auctionactivitydata.getList().get(i).getTime() * 1000, auctionactivitydata.getList().get(i).getStart() * 1000
                                    , auctionactivitydata.getList().get(i).getMid(), auctionactivitydata.getList().get(i).getUsername()));
                            }
                            if (auctionactivitydata.getList().get(i).getStart() != 0)
                            {
                                isStartMap.put(auctionactivitydata.getList().get(i).getId(), true);
                            }
                            else {
                                isStartMap.put(auctionactivitydata.getList().get(i).getId(), false);
                            }
                            updateBean.put(auctionactivitydata.getList().get(i).getId(),new UpdateAuctionBean());
                            lastperiodBean.put(auctionactivitydata.getList().get(i).getId(),new UpdateAuctionBean());
                            // }
                        }

//                        if(isUpdateUsername)
//                        {
//                            //  handler1.post(mRunnable3);
//                        }
//                        else
//                        {

                        AdapterListData();
                        //}
                    }
                }
                //更新商品竞买时间，价格，出价人
                if(action.equals(WebSocketService1.ACTION_JOINBACK1))
                {
                    auction_joinBackData = (Auction_JoinBackData)intent.getBundleExtra("bundle3").getSerializable("AuctionJoinBack");
                    String code = auction_joinBackData.getCode();
                    if(code!=null&&!code.equals(""))
                    {
                        if(Integer.parseInt(code)>0)
                        {
                            ObjectUtils.toast(mcontext,auction_joinBackData.getMsg());
                        }
                    }

                    if(temporary_listdata!=null) {
                        boolean isupdateusername = false;
                        for (int i = 0; i < temporary_listdata.size(); i++) {
                            int id = Integer.parseInt(temporary_listdata.get(i).getId());
                            if (auction_joinBackData.getId() == id) {

                                if(auction_joinBackData.getUsername()!=null&&auction_joinBackData.getPrice()>0)
                                {
                                    isupdateusername = true;
                                    UpdateAuctionBean update = new UpdateAuctionBean();
                                    update.setUsername(auction_joinBackData.getUsername());
                                    update.setPrice(auction_joinBackData.getPrice());
                                    updateBean.put(temporary_listdata.get(i).getId(),update);
                                    if(auction_joinBackData.getTime()>0)
                                    {
                                        temporary_listdata.get(i).setTime(auction_joinBackData.getTime() * 1000);
                                        break;
                                    }
                                    break;
                                }
                            }
                        }
                        if(isupdateusername)
                        {
                            handler1.post(mRunnable3);
                        }
                    }
                }
//                   if(action.equals(WebSocketService.ACTION_Nav))
//                   {
//                       navData= (Auction_NavData) intent.getBundleExtra("bundle2").getSerializable("AuctionNav");
//                       GetMenus();
//                   }

            }
        };
        IntentFilter myIntentFilter = new IntentFilter();
        myIntentFilter.addAction(WebSocketService1.ACTION_NOT1);
        myIntentFilter.addAction(WebSocketService1.ACTION_AUCTION1);
        myIntentFilter.addAction(WebSocketService1.ACTION_JOINBACK1);

        // myIntentFilter.addAction(WebSocketService.ACTION_Nav);
        //注册广播
        mcontext.registerReceiver(mBroadcastReceiver, myIntentFilter);
    }
    /**
     * 处理竞买返回通知消息
     */
    private void DealWithResult()
    {
        /**
         * 竞买返回通知重开
         */
        if(auctionResultData.getTime()>0&&auctionResultData.getStart()>0)
        {
            /**
             * 更新重开的商品时间
             */
            if (temporary_listdata != null) {
                for (int i = 0; i < temporary_listdata.size(); i++) {
                    int id = Integer.parseInt(temporary_listdata.get(i).getId());
                    if (auctionResultData.getId() .equals( id)) {
                        temporary_listdata.get(i).setTime(auctionResultData.getTime() * 1000);
                        temporary_listdata.get(i).setStart(auctionResultData.getStart() * 1000);
                        isStartMap.put(temporary_listdata.get(i).getId(), true);
                        break;
                    }
                }
            }
            /**
             * 有人中拍时
             */
            if(auctionResultData.getMid()>0)
            {
                /**
                 * 更新上期中拍商品活动状态和数据
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setUsername(auctionResultData.getUsername());
                update.setIspass_in(false);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
            /**
             * 无人中拍时
             */
            else
            {
                /**
                 * 更新上期流拍商品活动状态
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setIspass_in(true);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
        }
        /**
         * 竞买返回通知不重开
         */
        else
        {
            /**
             *
             */
//           if(auction_style.equals("mine_auctioning")) {
//               if (listdata != null) {
//                   for (int i = 0; i < listdata.size(); i++) {
//                       int id = Integer.parseInt(listdata.get(i).getId());
//                       if (auctionResultData.getId() == id) {
//                           listdata.remove(i);
//                           break;
//                       }
//                   }
//               }
//               if (myViewHolderList.containsKey(auctionResultData.getId())) {
//                   myViewHolderList.remove(auctionResultData.getId());
//               }
//           }
            /**
             * 有人中拍时
             */
            if(auctionResultData.getMid()>0)
            {

                /**
                 * 更新上期中拍商品活动状态和数据
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setUsername(auctionResultData.getUsername());
                update.setIspass_in(false);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
            /**
             * 无人中拍时
             */
            else
            {
                /**
                 * 更新上期流拍商品活动状态
                 */
                UpdateAuctionBean update = new UpdateAuctionBean();
                update.setIspass_in(true);
                lastperiodBean.put(auctionResultData.getId()+"",update);
                handler1.post(mRunnable4);
            }
        }
    }
    /**
     * 适配商品列表
     */
    private void AdapterListData()
    {
        mRefreshLayout.setRefreshing(false);
        ObjectUtils.GetDataNet(clickResetnetwork, progress, 1);
        if (page == 1) {

            adapter.setNewData(listdata);
        } else {
            adapter.addData(listdata);
        }
        mRecyclerView.setLayoutManager(layoutmanager);
        mRecyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        if (auctionactivitydata.getList().size() < 10 && page == 1) {
            adapter.loadMoreComplete();
            adapter.loadMoreEnd();
        }

    }
    private Handler handler1 = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            switch (msg.what) {
                case 1:
                    adapter.notifyTimeData();
                    break;
                case 2:
                    adapter.notifyDataSetChanged();
                    break;
                case 3:
                    adapter.notifyUsernameData();
                    break;
                case 4:
                    adapter.notifyLastPeriod();
                    break;

            }
        }
    };
    //更新上一期活动是否流拍
    private Runnable mRunnable4 = new Runnable() {
        @Override
        public void run() {
            if (null == message4) {
                message4 = new Message();
            } else {
                message4 = Message.obtain();
            }
            message4.what = 4;
            //发送信息给handler
            handler1.sendMessage(message4);
        }
    };
    //更新当前出价和竞拍人
    private Runnable mRunnable3 = new Runnable() {
        @Override
        public void run() {
            if (null == message3) {
                message3 = new Message();
            } else {
                message3 = Message.obtain();
            }
            message3.what = 3;
            //发送信息给handler
            handler1.sendMessage(message3);
        }
    };
    //更新商品是否过期
    private Runnable mRunnable2 = new Runnable() {
        @Override
        public void run() {
            if (null == message2) {
                message2 = new Message();
            } else {
                message2 = Message.obtain();
            }
            message2.what = 2;
            //发送信息给handler
            handler1.sendMessage(message2);
        }
    };
    //更新商品时间
    private Runnable mRunnable = new Runnable(){

        @Override
        public void run() {
            if( temporary_listdata!=null) {
                for (int i = 0; i <  temporary_listdata.size(); i++) {

                    int time =  temporary_listdata.get(i).getTime();
                    int start =  temporary_listdata.get(i).getStart();

                    if (start > 0) {
                        start = start - 40;
                        temporary_listdata.get(i).setStart(start);
                    }
                    if (time > 0) {
                        time = time - 40;
                        temporary_listdata.get(i).setTime(time);

                    }
                }
            }
            if (null == message) {
                message = new Message();
            } else {
                message = Message.obtain();
            }
            message.what = 1;
            //发送信息给handler
            handler1.sendMessage(message);
            //每40豪秒重启一下线程
            handler1.postDelayed(mRunnable, 40);
        }
    };



    public class AdaptList extends BaseMultiItemQuickAdapter<AuctionActivityData.ListBean,MytimeViewHolder> {
        private String type;
        private FragmentActivity mcontext;
        private int limitposition;
        public ArrayList<AuctionActivityData.ListBean> data = new ArrayList();
        public AdaptList(FragmentActivity context, ArrayList<AuctionActivityData.ListBean> data, String type) {
            super(data);
            this.data=data;
            this.mcontext = context;
            this.type = type;
            addItemType(AuctionActivityData.ListBean.THREE, R.layout.item_ry_fragment3);
        }



        @Override
        protected void convert(MytimeViewHolder holder,AuctionActivityData.ListBean mainlistdata) {
            switch (holder.getItemViewType()) {
                case AuctionActivityData.ListBean.THREE:
                    if(!(myViewHolderList.containsKey(mainlistdata.getId()))) {
                        myViewHolderList.put(mainlistdata.getId(), holder);
                        holder.setTime_position(holder.getLayoutPosition());
                        //判断list里面是否含有该holder，没有就增加
                        //因为list已经持有holder的引用，所有数据自动会改变
                        int time = mainlistdata.getTime();
                        String minute = String.format("%02d", time / 1000 / 60);
                        String second = String.format("%02d", time / 1000 % 60);
                        String millsecond = "00";
                        if (time % 1000 == 0) {
                            millsecond = String.format("%02d", 99);
                        } else {
                            millsecond = String.format("%02d", time % 1000 / 40 * 4);
                        }
                        holder.setText(R.id.kill_millsecond, millsecond);
                        holder.setText(R.id.kill_minute, minute);
                        holder.setText(R.id.kill_second, second);
                        ObjectUtils.photo2(mContext, mainlistdata.getThumb(), ((ImageView) holder.getView(R.id.item_grid_aishang_img)));
                        // holder.setText(R.id.rightnow_phone, mainlistdata.getUsername());
                        holder.setText(R.id.item_rightnow_price, "当前价: ￥" + mainlistdata.getPrice());
                        holder.setText(R.id.item_grid_detail_like_title, mainlistdata.getTitle());
                        holder.addOnClickListener(R.id.rightnow_openteam);
                    }
                    break;
            }
        }

        //更新当前出价竞拍人
        public void notifyUsernameData() {
            if(listdata!=null) {
                for (int i = 0; i <  temporary_listdata.size(); i++) {
                    String id =  temporary_listdata.get(i).getId();
                    if (myViewHolderList.containsKey(id)) {
                        if(updateBean.get(id).getPrice()>0) {
                            myViewHolderList.get(id).getItem_rightnow_ll().setVisibility(View.VISIBLE);
                            myViewHolderList.get(id).getItem_lastperiod_failed().setVisibility(View.GONE);
                            myViewHolderList.get(id).getItem_lastperiod_ll().setVisibility(View.GONE);
                           // myViewHolderList.get(id).getItem_rightnow_person().setText(updateBean.get(id).getUsername());
                            myViewHolderList.get(id).getItem_rightnow_price().setText("当前价: ￥" + updateBean.get(id).getPrice());
                        }
                    }
                }
            }
        }
        //更新上期商品活动是否流拍
        public void notifyLastPeriod() {
            if(listdata!=null) {
                for (int i = 0; i <  temporary_listdata.size(); i++) {
                    String id = temporary_listdata.get(i).getId();
                    if (myViewHolderList.containsKey(id)) {
                        if(lastperiodBean.get(id).ispass_in())
                        {
                            myViewHolderList.get(id).getItem_rightnow_ll().setVisibility(View.GONE);
                            myViewHolderList.get(id).getItem_lastperiod_failed().setVisibility(View.VISIBLE);
                            myViewHolderList.get(id).getItem_lastperiod_ll().setVisibility(View.GONE);
                        }
                        else
                        {
                            myViewHolderList.get(id).getItem_rightnow_ll().setVisibility(View.GONE);
                            myViewHolderList.get(id).getItem_lastperiod_failed().setVisibility(View.GONE);
                            myViewHolderList.get(id).getItem_lastperiod_ll().setVisibility(View.VISIBLE);
                            myViewHolderList.get(id).getItem_lastperiod_person().setText(lastperiodBean.get(id).getUsername());
                        }
                    }
                }
            }
        }
        //更新全部商品时间
        public void notifyTimeData(){
            if( temporary_listdata!=null) {
                    for (int i = 0; i <  temporary_listdata.size(); i++) {
                        int time =  temporary_listdata.get(i).getTime();
                        int start =  temporary_listdata.get(i).getStart();
                        if (myViewHolderList.containsKey( temporary_listdata.get(i).getId())) {
                            boolean isstart = isStartMap.get( temporary_listdata.get(i).getId());
                            //没有start时间时
                            if (time > 0 && !isstart) {
                                myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setEnabled(true);
                                myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setBackgroundResource(R.drawable.corner_red_bg_selector);
                            }//有start时间时
                            else {

                                //开始参加竞买
                                if (isstart && start <= 0) {
                                    myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setEnabled(true);
                                    myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setBackgroundResource(R.drawable.corner_red_bg_selector);
                                } else {
                                    myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setEnabled(false);
                                    myViewHolderList.get( temporary_listdata.get(i).getId()).getRightnow_openteam().setBackgroundResource(R.drawable.corner_gray_bg);
                                }
                            }
                            //只要竞买还没结束
                            if (time >= 0) {

                                String minute = String.format("%02d", time / 1000 / 60);
                                String second = String.format("%02d", time / 1000 % 60);
                                String millsecond = String.format("%02d", time % 1000 / 40 * 4);
                                myViewHolderList.get( temporary_listdata.get(i).getId()).getKill_millsecond().setText(millsecond);
                                myViewHolderList.get( temporary_listdata.get(i).getId()).getKill_minute().setText(minute);
                                myViewHolderList.get( temporary_listdata.get(i).getId()).getKill_second().setText(second);

                            }
                        }
                }
            }

        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
